
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    choice: true,
    headType: 2,          // 抬头类型
    headName: '',         // 抬头名称
    identityNumber: ''    // 识别号
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  //内容切换
  isShow(e) {
    const show = e.currentTarget.dataset.show;
    this.setData({
      show
    })
  },
  //选择抬头
  choiceType(e){
    const type = e.currentTarget.dataset.type;
    let headType; 
    type ? headType = 1 : headType = 2;
    this.setData({
      headType,
      choice: !type
    })
  },
  //单位名称
  name(e){
    const headName = e.detail.value;
    this.setData({
      headName
    })
  },
  //识别号
  number(e) {
    const identityNumber = e.detail.value;
    this.setData({
      identityNumber
    })
  },
  //确认
  sure(){
    if( 1 == this.data.headType ){
      if (!app.validate(this.data.headName, 'required')) {
        app.showModal('请输入单位名称');
        return;
      }
      if (!app.validate(this.data.identityNumber, 'alphanumeric')) {
        app.showModal('请输入纳税人识别号');
        return;
      }
    }
    const invoice = {
      headType: this.data.headType,
      headName: this.data.headName,
      identityNumber: this.data.identityNumber
    }
    wx.setStorageSync('invoice', invoice)
    wx.navigateBack();
  }
})